package com.ex.himoffice.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.ex.himoffice.DB.DbClose;
import com.ex.himoffice.DB.DbSet;
import com.ex.himoffice.Vo.QnaVo;



public class QnaDao {
	public int getSeq(){
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		
		int QNA_SEQ = 0;
		String seqQuery = "SELECT NVL(MAX(QNA_SEQ), 0) +1 FROM TB_QNA";
		
		try {
			conn = DbSet.getConnection();
			pstmt = conn.prepareStatement(seqQuery);
			
			rs = pstmt.executeQuery();
			if(rs.next()){
				QNA_SEQ = rs.getInt(1);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			DbClose.close(rs, pstmt, conn);
		}
		return QNA_SEQ;
	}
	public int qnaInsert(QnaVo param){
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		
		int seq_no = getSeq();
		int succ = 0;
		String insertQuery = "INSERT INTO TB_QNA(QNA_SEQ, SSO_ID, TITLE, CONTENT, QNA_DATE) "
				+ " VALUES(?, ? , ? , ? , TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'))";
		
		try {
			conn = DbSet.getConnection();
			pstmt = conn.prepareStatement(insertQuery);
			
			pstmt.setInt(1, seq_no);
			pstmt.setString(2, param.getSSO_ID());
			pstmt.setString(3, param.getTITLE());
			pstmt.setString(4, param.getCONTENT());
			succ = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			System.out.print("QNADAO qnaInsert");
			e.printStackTrace();
		}
		finally{
			DbClose.close(rs, pstmt, conn);
		}
		return succ;
	}
	
	public ArrayList<QnaVo> qnaList(QnaVo param){
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		
		String listQuery = "SELECT * FROM ";
		
		ArrayList<QnaVo> list = null;
		
		return list;
	}
}
